package com.jlcloud.core.xss.processor;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.jlcloud.core.xss.JlCloudXssProperties;
import com.jlcloud.core.xss.XssHolder;
import com.jlcloud.core.xss.XssType;
import com.jlcloud.core.xss.XssUtil;

import java.io.IOException;

/**
 * jackson xss 处理
 *
 * @author By: JlCloud <br>
 * @Package: com.jlcloud <br>
 * @CreateTime: 2024-12-03 21:45 <br>
 * @Copyright: 2021 www.jilianjituan.com Inc. All rights reserved. <br>
 * @Caution 注意：本内容仅限于冀联人力集团内部传阅，禁止外泄以及用于其他的商业目的 <br>
 */
@Slf4j
@RequiredArgsConstructor
public class JacksonXssClean extends XssDeserializerBase {
	private final JlCloudXssProperties properties;
	private final XssCleaner xssCleaner;

	@Override
	public String clean(String name, String text) throws IOException {
		if (text == null) {
			return null;
		}
		// 判断是否忽略
		if (XssHolder.isIgnore(name)) {
			return XssUtil.trim(text, properties.isTrimText());
		}
		String value = xssCleaner.clean(name, XssUtil.trim(text, properties.isTrimText()), XssType.JACKSON);
		log.debug("Json property name:{} value:{} cleaned up by jlcloud-xss, current value is:{}.", name, text, value);
		return value;
	}

}
